<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象习题</title>
</head>
<body>
    <script type="text/javascript">
    var collection = {
        "1275":{
            "album":"依然范特西",
            "artist":"周杰伦",
            "tracks":[
                "听妈妈的话",
                "千里之外"
            ]
    },
        "2468":{
            "album":"西界",
            "artist":"林俊杰",
            "tracks":[
                "西界",
                "杀手"
            ]
    },
        "3245":{
            "artist":"许嵩",
            "tracks":[ ]
        },
        "5439":{
            "album":"遇见"
        }
    }

    // 1.定义方法更新记录:
    // function updateRecords(id,prop,value)
    // 要求：
    // 1).如果传入的value是一个空值，表示将该属性删除
    // 2).传入的prop如果是tracks，则代表添加，其他是修改
    function updateRecords(id,prop,value){
        this.id = id;
        this.prop = prop;
        this.value = value;
        // if ( value = '' ) {
        //     delete collection.id.tracks
        // }
        value == '' ? delete collection.id.tracks : value ;
        prop == collection.id.tracks ? collection.id.tracks.push(value) : collection.id.album = value;

        console.log( collection.id );
        
    }
    // 3245 tracks '有何不可'
    // 3245 tracks ''   -->删
    // 5439 artist '孙燕姿'
    // 5439 album '逆光'

    var Tools = updateRecords('3245','tracks','');


    </script>
    
</body> 
</html>